package com.bloveoacom.util;

import android.support.annotation.DrawableRes;
import android.widget.ImageView;


import com.bloveoacom.weichi.R;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.transition.DrawableCrossFadeFactory;

import jp.wasabeef.glide.transformations.BlurTransformation;

import static com.bumptech.glide.request.RequestOptions.bitmapTransform;


/**
 * author: zhu.px
 * e-mail: 1271901673@qq.com
 * time  : 2018/5/28
 * desc  : 图片加载
 */
public class GlideUtil {

    public static final int header = R.drawable.ic_header_default;
    public static final int default_err = R.drawable.ic_pic_default;

    public static void loadImage(ImageView iv, String url) {
        GlideApp.with(iv.getContext())
                .load(url)
                .placeholder(default_err)
                .error(default_err)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .centerCrop()
                //.transition(DrawableTransitionOptions.withCrossFade(new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true)))
                .into(iv);
    }

    public static void loadLocationImage(ImageView iv, Integer url) {
        GlideApp.with(iv.getContext())
                .load(url)
                .centerCrop()
                .placeholder(default_err)
                .error(default_err)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
               // .transition(DrawableTransitionOptions.withCrossFade(new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true)))
                .into(iv);
    }

    public static void loadCircleImage(ImageView iv, Object url) {
        GlideApp.with(iv.getContext())
                .load(url)
                .circleCrop()
                .placeholder(header)
                .error(header)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                //.transition(DrawableTransitionOptions.withCrossFade(new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true)))
                .into(iv);
    }

    public static void loadCircleImage(ImageView iv, @DrawableRes int resId) {
        GlideApp.with(iv.getContext())
                .load(resId)
                .circleCrop()
                .placeholder(default_err)
                .error(default_err)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                //.transition(DrawableTransitionOptions.withCrossFade(new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true)))
                .into(iv);
    }

    public static void loadRoundmage(ImageView iv, String url) {
        GlideApp.with(iv.getContext())
                .load(url)
                .placeholder(default_err)
                .error(default_err)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .transform(new MultiTransformation<>(new CenterCrop(), new RoundedCorners(15)))
                //.transition(DrawableTransitionOptions.withCrossFade(new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true)))
                .into(iv);
    }
    public static void loadRoundmage2(ImageView iv, String url) {
        GlideApp.with(iv.getContext())
                .load(url)
                .placeholder(default_err)
                .error(default_err)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .transform(new MultiTransformation<>(new CenterCrop(), new RoundedCorners(15)))
                //.transition(DrawableTransitionOptions.withCrossFade(new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true)))
                .into(iv);
    }
    public static void loadImageForBlur(ImageView iv, String url) {
        GlideApp.with(iv.getContext())
                .load(url)
                .placeholder(default_err)
                .error(default_err)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .centerCrop()
                //.transition(DrawableTransitionOptions.withCrossFade(new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true)))
                .apply(bitmapTransform(new BlurTransformation(200)))
                .into(iv);
    }




}
